﻿using Microsoft.EntityFrameworkCore;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.BackgroundJobs.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.FeatureManagement.EntityFrameworkCore;
using Volo.Abp.Identity;
using Volo.Abp.Identity.EntityFrameworkCore;
using Volo.Abp.IdentityServer.EntityFrameworkCore;
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Abp.TenantManagement;
using Volo.Abp.TenantManagement.EntityFrameworkCore;

using Logistics.Model;

namespace Logistics.EntityFrameworkCore
{
    [ReplaceDbContext(typeof(IIdentityDbContext))]
    [ReplaceDbContext(typeof(ITenantManagementDbContext))]
    [ConnectionStringName("Default")]
    public class LogisticsDbContext : 
        AbpDbContext<LogisticsDbContext>,
        IIdentityDbContext,
        ITenantManagementDbContext
    {
        /* Add DbSet properties for your Aggregate Roots / Entities here. */
        
        #region Entities from the modules
        
        /* Notice: We only implemented IIdentityDbContext and ITenantManagementDbContext
         * and replaced them for this DbContext. This allows you to perform JOIN
         * queries for the entities of these modules over the repositories easily. You
         * typically don't need that for other modules. But, if you need, you can
         * implement the DbContext interface of the needed module and use ReplaceDbContext
         * attribute just like IIdentityDbContext and ITenantManagementDbContext.
         *
         * More info: Replacing a DbContext of a module ensures that the related module
         * uses this DbContext on runtime. Otherwise, it will use its own DbContext class.
         */
        
        //Identity
        public DbSet<IdentityUser> Users { get; set; }
        public DbSet<Founder> Founder { get; set; }
        public DbSet<Statistics> Statistics { get; set; }
        public DbSet<IdentityRole> Roles { get; set; }
        public DbSet<IdentityClaimType> ClaimTypes { get; set; }
        public DbSet<Claim> Claim { get; set; }
        public DbSet<OrganizationUnit> OrganizationUnits { get; set; }
        public DbSet<IdentitySecurityLog> SecurityLogs { get; set; }
        public DbSet<IdentityLinkUser> LinkUsers { get; set; }
        
        // Tenant Management
        public DbSet<Tenant> Tenants { get; set; }
        public DbSet<TenantConnectionString> TenantConnectionStrings { get; set; }

        #endregion
        
        public LogisticsDbContext(DbContextOptions<LogisticsDbContext> options)
            : base(options)
        {

        }
        public DbSet<ApprovalConditions> ApprovalConditions { get; set; }
        public DbSet<ApprovalActivity> ApprovalActivity { get; set; }
        public DbSet<ApprovalHistory> ApprovalHistory { get; set; }
        public DbSet<Basic> Basic { get; set; }
        public DbSet<Become> Become { get; set; }
        public DbSet<Cargoowner> Cargoowner { get; set; }
        public DbSet<Carry> Carry { get; set; }
        public DbSet<Currency> Currency { get; set; }
        public DbSet<Deptinfo> Deptinfo { get; set; }
        public DbSet<invoice> invoice { get; set; }
        public DbSet<Material> Material { get; set; }
        public DbSet<MaterialType> MaterialType { get; set; }
        public DbSet<Operator> Operator { get; set; }
        public DbSet<OperatorLinkRole> OperatorLinkRole { get; set; }
        public DbSet<Payment> Payment { get; set; }
        public DbSet <PositionInfo> PositionInfo { get; set; }
        public DbSet<PowerManager> PowerManager { get; set; }
        public DbSet<ProcessConfiguration> ProcessConfiguration { get; set; }
        public DbSet<Procurement> Procurement { get; set; }
        public DbSet<ReceiptsAndPayments> ReceiptsAndPayments { get; set; } 
        public DbSet<RoleLinkPower> RoleLinkPower { get; set; }
        public DbSet<RoleManage> RoleManage { get; set; }
        public DbSet<Superior> Superior { get; set; }
        public DbSet<Warehousing> Warehousing { get; set; }
        public DbSet<Accident> Accident { get; set; }
        public DbSet<ApprovalProcess> ApprovalProcess { get; set; }
        public DbSet<ApprovalStatus> ApprovalStatus { get; set; }
        public DbSet<Carriercontracttracking> Carriercontracttracking { get; set; }
        public DbSet<Contracttracking> Contracttracking { get; set; }
        public DbSet<Cost> Cost { get; set; }
        public DbSet<Cost2> Cost2 { get; set; }
        public DbSet<Destination> Destination { get; set; }
      
        public DbSet<Entry> Entry { get; set; }
        public DbSet<Field> Field { get; set; }
        public DbSet<Fix> Fix { get; set; }
        public DbSet<Line> Line { get; set; }
        public DbSet<Maintain> Maintain { get; set; }
        public DbSet<Origin> Origin { get; set; }
        public DbSet<Owner> Owner { get; set; }
        public DbSet<Tyre> Tyre { get; set; }
        public DbSet<UserLog> UserLog { get; set; }
        public DbSet<Vehicle> Vehicle { get; set; }
        public DbSet<Violation> Violation { get; set; }
        public DbSet<Dimission> Dimission { get; set; }
        public DbSet<Longitudeandlatitude> Longitudeandlatitude { get; set; }


        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            /* Include modules to your migration db context */

            builder.ConfigurePermissionManagement();
            builder.ConfigureSettingManagement();
            builder.ConfigureBackgroundJobs();
            builder.ConfigureAuditLogging();
            builder.ConfigureIdentity();
            builder.ConfigureIdentityServer();
            builder.ConfigureFeatureManagement();
            builder.ConfigureTenantManagement();

            /* Configure your own tables/entities inside here */

            //builder.Entity<YourEntity>(b =>
            //{
            //    b.ToTable(LogisticsConsts.DbTablePrefix + "YourEntities", LogisticsConsts.DbSchema);
            //    b.ConfigureByConvention(); //auto configure for the base class props
            //    //...
            //});
        }
    }
}
